﻿using System;
using System.Collections.Specialized;
using System.Dynamic;
using System.Web;
using System.Web.UI;

namespace Nydus.WebForms.FrontendModel
{
    public class BasePage : Page
    {

    }

    /// <summary>
    /// Base class for all user controls
    /// </summary>
    /// <typeparam name="TModel">The type of the model.</typeparam>
    public class BasePage<TModel> : BasePage, IView<TModel>
    {
        /// <summary>
        /// Gets or sets the model.
        /// </summary>
        /// <value>
        /// The model.
        /// </value>
        public TModel Model { get; set; }

        /// <summary>
        /// Gets or sets the view data.
        /// </summary>
        /// <value>
        /// The view data.
        /// </value>
        public dynamic ViewData
        {
            get
            {
                if(viewData == null)
                    viewData = new ExpandoObject();

                return viewData;
            }
        }
        private dynamic viewData;

        /// <summary>
        /// Get query string parameters from Request.QueryString
        /// </summary>
        public NameValueCollection QueryString
        {
            get
            {
                return Request.QueryString;
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            if (IsPostBack)
            {
                BindModelData();
            }
            base.OnLoad(e);
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            DataBind();
        }

        protected virtual void BindModelData()
        {

        }
    }
}
